package com.wendy.common.core.errcode.base;

import com.wendy.common.core.constant.HttpStatus;
import com.wendy.common.core.exception.base.BusinessException;

import java.io.Serializable;

public class BaseError implements Serializable {
    private static final long serialVersionUID = 1L;

    protected static BaseError BASE_ERROR() {
        return new BaseError("操作失败", HttpStatus.ERROR);
    }


    protected static BaseError MOVED_PERM() {
        return new BaseError("资源已被移除", HttpStatus.MOVED_PERM);
    }


    protected static BaseError SEE_OTHER() {
        return new BaseError("重定向", HttpStatus.SEE_OTHER);
    }


    protected static BaseError NOT_MODIFIED() {
        return new BaseError("资源没有被修改", HttpStatus.NOT_MODIFIED);
    }


    protected static BaseError BAD_REQUEST() {
        return new BaseError("参数列表错误", HttpStatus.BAD_REQUEST);
    }


    protected static BaseError UNAUTHORIZED() {
        return new BaseError("未授权", HttpStatus.UNAUTHORIZED);
    }


    protected static BaseError FORBIDDEN() {
        return new BaseError("访问受限，授权过期", HttpStatus.FORBIDDEN);
    }


    protected static BaseError NOT_FOUND() {
        return new BaseError("服务未找到", HttpStatus.NOT_FOUND);
    }


    protected static BaseError BAD_METHOD() {
        return new BaseError("不允许的http方法", HttpStatus.BAD_METHOD);
    }


    protected static BaseError CONFLICT() {
        return new BaseError("资源冲突", HttpStatus.CONFLICT);
    }


    protected static BaseError UNSUPPORTED_TYPE() {
        return new BaseError("不支持的数据，媒体类型", HttpStatus.UNSUPPORTED_TYPE);
    }


    protected static BaseError ERROR() {
        return new BaseError("系统内部错误", HttpStatus.ERROR);
    }


    protected static BaseError NOT_IMPLEMENTED() {
        return new BaseError("接口未实现", HttpStatus.NOT_IMPLEMENTED);
    }

    protected static BaseError BASE_ERROR_WARN() {
        return new BaseError("系统警告,请联系管理员 ", HttpStatus.WARN);
    }



    private String msg;
    private Integer code;

    public BaseError() {
    }

    public BaseError(String msg, Integer code) {
        this.msg = msg;
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public void fire() {
        throw new BusinessException(this.msg, this.code);
    }

    public void formatFire(String... args) {
        throw new BusinessException(String.format(this.msg, args), this.code);
    }

    @Override
    public String toString() {
        return "BaseError{" +
                "msg='" + msg + '\'' +
                ", code=" + code +
                '}';
    }

}
